package cn.script.game.dup;

import cn.script.call_api.AfterApi;
import cn.script.call_api.BeforeApi;
import cn.script.common.CoordConst;
import cn.script.domain.Point;
import cn.script.domain.RangePoint;
import cn.script.exception.StopException;
import cn.script.game.GameOpt;
import cn.script.game.opt.DefaultOpt;
import cn.script.game.prof.Pi;
import cn.script.util.LogOut;

/**
 * 生死副本
 *
 * @author 周永波
 */
public class SsDup extends AbstractDup {

    private GameOpt gop;

    private String teamName;

    private String cityName;

    private boolean killBoss;

    public SsDup(Pi pi, GameOpt go, GameOpt gop, String cityName, String teamName, boolean boss) {
        super("生死劫最后的救赎", pi, go);
        this.gop = gop;
        this.cityName = cityName;
        this.teamName = teamName;
        this.killBoss = boss;
    }


    public BeforeApi zscs() {
        return () -> {
            this.go.team(this.teamName, this.cityName, this.gop);
            this.go.toBack();
            this.go.moveTo("凌霄城").winPoint(415, 293).gamePoint(181, 169).opt();
            this.go.npc("天朝警备");
            this.go.text_click("修仙传送");
            this.go.text_click("生死副本");
            this.go.wio().leftClick(Point.point(563, 90), 500);
            this.go.text_click("开启战斗");
            this.gop.toCity(this.cityName);
            return 1;
        };
    }

    public BeforeApi hycs() {
        return () -> {
            this.go.team(this.teamName, this.cityName, this.gop);
            this.go.toBack();
//        this.go.moveTo("凌霄城").winPoint(415, 293).gamePoint(181, 169).opt();
            this.go.npc("会员服务员");
            this.go.text_click("会员副本传送");
            this.go.text_click("生死副本");
            this.go.wio().leftClick(Point.point(563, 90), 500);
            this.go.text_click("开启战斗");
            this.gop.toCity(this.cityName);
            DefaultOpt.defaultSkill(this.go, 3);
            return 1;
        };
    }

    @Override
    protected BeforeApi beFore() {
        return this.hycs();
    }

    @Override
    protected AfterApi after() {

        return null;
    }

    @Override
    public DupInfo dupInfo() {
        DupInfo dupInfo = new DupInfo(this.go, this.optName, this.pi.skills());
        dupInfo.dupOpt("生死劫嗜魂")
                .m_winPoint(584, 300)
                .m_gamePoint(136, 46)
                .m_rPoint(6, 6)
                .a_endNum(5)
                .a_timeOut(35000)
                .beFore(() -> {
                    this.just(RangePoint.rp(458, 373, 141, 113), null);
                    this.just(null, Point.point(316, 48));
                    return 1;
                });
        if (this.killBoss) {
            LogOut.out("只kill最后的boss");
            return dupInfo;
        }
        dupInfo.dupOpt("生死劫诛神")
                .m_winPoint(510, 232)
                .m_gamePoint(83, 30)
                .m_rPoint(6, 6)
                .a_endNum(5)
                .a_timeOut(20000)
                .beFore(() -> {
                    this.just(RangePoint.rp(469, 334, 124, 91), Point.point(455, 9));
                    return 1;
                });

        dupInfo.dupOpt("生死劫泣血")
                .m_winPoint(355, 270)
                .m_gamePoint(62, 86)
                .m_rPoint(6, 6)
                .a_endNum(5)
                .a_timeOut(25000)
                .beFore(() -> {
                    this.just(RangePoint.rp(406, 236, 62, 54), Point.point(11, 124));
                    return 1;
                });

        dupInfo.dupOpt("生死劫残念")
                .m_winPoint(196, 282)
                .m_gamePoint(29, 134)
                .m_rPoint(6, 6)
                .a_endNum(5)
                .a_timeOut(25000)
                .beFore(() -> {
                    this.just(RangePoint.rp(323, 282, 62, 102), Point.point(14, 385));
                    return 1;
                });

        dupInfo.dupOpt("生死劫炼狱")
                .m_winPoint(162, 304)
                .m_gamePoint(33, 153)
                .m_rPoint(6, 6)
                .a_endNum(5)
                .a_timeOut(25000);

        return dupInfo;
    }

    /**
     * 冰法副本跳跃点
     *
     * @param m_point
     * @param just_point
     */
    public void just(RangePoint m_point, Point just_point) {
        if (m_point != null) {
            this.go.moveTo(this.optName)
                    .winPoint(m_point.ps())
                    .gamePoint(m_point.pe()).opt();
        }
        Point oldPoint = this.go.gi().nowCd();
        if (just_point == null) {
            this.go.wio().leftClickStr("定点", "000000",
                    Point.point(22, 26), CoordConst.WIN);
        } else {
            this.go.wio().leftClick(just_point, 200);
        }
        this.go.wio().keypress("f5", 1000);
        Point newPoint = this.go.gi().nowCd();
        if (newPoint.x() != oldPoint.x() && newPoint.y() != oldPoint.y()) {
            return;
        }
        LogOut.out("冰法定点跳跃失败");
        throw new StopException();
    }
}
